/**
 *
 */
package com.ybkj.daijia.server.service.impl;


import com.ybkj.daijia.page.Page;
import com.ybkj.daijia.page.Pageable;
import com.ybkj.daijia.page.impl.PageImpl;
import com.ybkj.daijia.page.impl.PageRequest;
import com.ybkj.daijia.server.mapper.DriverRechargeRecordMapper;
import com.ybkj.daijia.server.model.DriverRechargeRecord;
import com.ybkj.daijia.server.service.DriverRechargeRecordService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Shine
 *
 */
@Service
public class DefaultDriverRechargeRecordService implements DriverRechargeRecordService {

    @Autowired
    private DriverRechargeRecordMapper driverRechargeRecordMapper;

    /* (non-Javadoc)
     * @see com.ybkj.shop.service.AdminService#queryAll()
     */
//	@Override
//	public Page<DriverRechargeRecord> queryAll(Long driverId,Date start,Date end) {
//		
//		Pageable pageable = new PageRequest(Pager.getPage(), Pager.getLimit());
//		
//		Map<String, Object> params = new HashMap<String, Object>();
//		params.put("driverId", driverId);
//		if(null!=start){
//			params.put("start", start);
//		}
//		if(null!=end){
//			params.put("end", end);
//		}
//		params.put("offset", Pager.getOffset());
//		params.put("size", Pager.getLimit());
//		
//		List<DriverRechargeRecord> content = driverRechargeRecordMapper.selectByParams(params);
//		long total = driverRechargeRecordMapper.countByParams(params);
//		
//		return new PageImpl<DriverRechargeRecord>(content, pageable, total);
//	}

//	@Override
//	public List<DriverRechargeRecord> listAll(Long driverId) {
//		
//		Map<String, Object> params = new HashMap<String, Object>();
//		params.put("driverId", driverId);
//		
//		List<DriverRechargeRecord> content = driverRechargeRecordMapper.selectByParams(params);
//		
//		return content;
//	}

//	@Transactional(rollbackFor=Exception.class)
//	public DriverRechargeRecord insertRecord(DriverRechargeRecord driverRechargeRecord) {
//		
//		driverRechargeRecordMapper.insertRecord(driverRechargeRecord);
//		
//		return driverRechargeRecord;
//	}

//	public DriverRechargeRecord findOne(Long id) {
//		
//		return driverRechargeRecordMapper.selectByPrimaryKey(id);
//	}

    @Override
    public Page<DriverRechargeRecord> rechargeRecord(Long driverId,
        Integer page, Integer limit) {

        Pageable pageable = new PageRequest(page, limit);

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("driverId", driverId);
        params.put("offset", page * limit);
        params.put("size", limit);

        List<DriverRechargeRecord> content = driverRechargeRecordMapper.selectByParams(params);
        long total = driverRechargeRecordMapper.countByParams(params);

        return new PageImpl<DriverRechargeRecord>(content, pageable, total);
    }

//	@Override
//	public Page<Map<String, Object>> findRebate(Long driverId,Integer page, Integer limit) {
//		Pageable pageable = new PageRequest(page, limit);
//		
//		Map<String, Object> params = new HashMap<String, Object>();
//		
//		params.put("driverId", driverId);
//		params.put("offset",  page*limit);
//		params.put("size", limit);
//		
//		List<DriverRechargeRecord> content = driverRechargeRecordMapper.selectRebate(params);
//		long total = driverRechargeRecordMapper.countRebate(params);
//		
//		List<Map<String, Object>> mapList=new ArrayList<Map<String,Object>>();
//		
//		if(org.apache.commons.collections.CollectionUtils.isNotEmpty(content)){
//			for (DriverRechargeRecord  d : content) {
//				Map<String, Object> map =new HashMap<String, Object>();
//				map.put("date", d.getCreated());
//				map.put("memo", d.getMemo());
//				map.put("money",d.getMoney());
//				mapList.add(map);
//			}
//		}
//
//		Page<Map<String, Object>> result = new PageImpl<Map<String, Object>>(mapList, pageable, total);
//		return  result;
//		
//	}

//	@Override
//	public BigDecimal sumByDriverAndType(Long driverId, Integer rechargeTypeRebate) {
//		BigDecimal totalMoney = driverRechargeRecordMapper.sumByDriverAndType(driverId,rechargeTypeRebate);
//		if(null==totalMoney){
//			return BigDecimal.ZERO;
//		}
//		return totalMoney;
//	}

    @Override
    public DriverRechargeRecord findByTypeAndOrderId(
        Integer type, Long orderId) {

        return driverRechargeRecordMapper.selectByTypeAndOrderId(type, orderId);
    }

    @Override
    public List<DriverRechargeRecord> listAll() {

        return driverRechargeRecordMapper.selectAll();

    }


}